﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

public partial class Sys_authorityadd : System.Web.UI.Page
{
    PM.PMSys.authority allauth = new PM.PMSys.authority();
    PM.Model.UserType mNewRole = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //不要改table的名称因为改了table的名称后得重新写脚本
            auth.InnerHtml = allauth.CreateAuthorityTable("1");
        }
    }

    protected void Submit_Authority(object sender, EventArgs e)
    {
        if (this.RoleName.Text.Trim() == string.Empty)
        {
            PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "角色名称不能为空！");
            return;
        }
        else if (this.RoleId.Text.Trim() == string.Empty)
        {
            PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "角色编号不能为空！");
            return;
        }
        else if (this.authvalues.Value.Trim() == string.Empty)
        {
            PM.Code.Web.alertmessage.ShowMsg(this.UpdatePanel1, "不允许有空权限的角色！");
            return;
        }
        else
        {
            if (Regex.IsMatch(this.RoleId.Text.Trim(), "^[1-9][0-9]*$"))
            {
                if (!allauth.CheckExist(Int32.Parse(this.RoleId.Text.Trim())))
                {
                    mNewRole = new PM.Model.UserType();
                    mNewRole.TypeName = RoleName.Text.Trim();
                    mNewRole.TypeId = Int32.Parse(RoleId.Text.Trim());
                    mNewRole.Rating = Rating.Value;
                    mNewRole.State = RoleState.Value == "1" ? true : false;
                    mNewRole.Fun = authvalues.Value.ToString() == "" ? "|" : authvalues.Value.ToString();
                    mNewRole.EnableFun = authvalues.Value.ToString() == "" ? "|" : authvalues.Value.ToString();
                    mNewRole.DisableFun = "|";
                    allauth.Insert_Authority(mNewRole);
                    RoleName.Text = "";
                    RoleId.Text = "";
                    PM.Code.Web.alertmessage.ShowMsg(UpdatePanel1, "添加成功！");
                }
            }
            else
                PM.Code.Web.alertmessage.ShowMsg(UpdatePanel1, "不允许非正整数的编号！");
        }
    }
}
